Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear db cache on startup #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

okraits
Copy link
Contributor

@okraits okraits commented Nov 9, 2018

Clear the cache for the users/roles/permissions datastructures on app startup. This ensures that the cache is always up to date, for example if a database import has been done before running the app.

@okraits
Copy link
Contributor Author

okraits commented Dec 3, 2018

@zaidka What about this one? ;-)

@zaidka
Copy link
Member

zaidka commented Dec 3, 2018

Won't this cause cache to clear whenever a new worker process starts?

@okraits
Copy link
Contributor Author

okraits commented Dec 4, 2018

I'm not sure. I verified the execution of the clear_permissions_cache method with log output. And the log output appeared only once. I will have a look again tomorrow.

@okraits
Copy link
Contributor Author

okraits commented Dec 5, 2018

I had a look at this once more. The clear_permissions_cache method is called per worker. This means that it is called more than once at startup if you run puma in clustered mode.

There's another possible place to clear the cache on startup, in config/puma.rb:

before_fork do
  # action
end

But I don't have access to the Rails or the GenieacsGUI object there AFAIK.

@zaidka Do you have an idea how to fix this?

@zaidka
Copy link
Member

zaidka commented Dec 6, 2018

Maybe clear the cache manually from console or using a rake command.

@okraits
Copy link
Contributor Author

okraits commented Dec 6, 2018

Well, then I'd rather have the disadvantage of getting the cache cleared too often than having to run a command manually 😁

@zaidka
Copy link
Member

zaidka commented Dec 6, 2018

Why not cache in memory instead?

@okraits
Copy link
Contributor Author

okraits commented Dec 6, 2018

You mean using MemoryStore as the cache store? (https://guides.rubyonrails.org/caching_with_rails.html#activesupport-cache-memorystore) Well, that's an option too, but then there's a cache per worker as I have understood it.

Should we go this way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants